package com.gzx.plugin.ams.modular.utils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.util.CommonCryptogramUtil;
import vip.xiaonuo.common.util.CommonHttpUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zjt
 * @description 临时使用
 * @date 2025/7/4 10:09
 */
@Slf4j
public class AmsSmsUtil {

    public static int sendNoticeSms(String phone, String message) {
        Map<String, Object> reqBody = new HashMap<>();
        reqBody.put("MchId", "1042154");
        reqBody.put("AppId", "10011710310751031");
        reqBody.put("Version", "1.2.0");
        reqBody.put("Type", "1");
        reqBody.put("SessionContext", "【天津普惠金融调解中心】" + message);
        reqBody.put("PhoneNumberSet", List.of(phone));
        long timeStamp = System.currentTimeMillis();
        reqBody.put("TimeStamp", timeStamp);
        reqBody.put("SignType", "MD5");
        String sb = "AppId=10011710310751031" +
                "&MchId=1042154" +
                "&SignType=MD5" +
                "&TimeStamp=" +
                timeStamp +
                "&Type=1&Version=1.2.0&key=148831340082495fbafaf8edab86ab91";
        reqBody.put("Signature", CommonCryptogramUtil.doMd5(sb).toUpperCase());
        String respBody = CommonHttpUtil.post("https://apis.shlianlu.com/sms/trade/normal/send", null, JSON.toJSONString(reqBody), "资产通知");
        log.info("调用联麓短信发送接口响应：{}", respBody);
        String status = JSONObject.parseObject(respBody).getString("status");
        if ("00".equals(status)) {
            return 1;
        } else {
            throw new CommonException("短信发送异常");
        }
    }
}
